package com.southpark.demo.control.services.http
{
	import com.southpark.framework.control.proxies.IProxy;
	import com.southpark.framework.control.services.IService;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.Responder;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	
	
	public class BaseHTTPService implements IService
	{
		private var service:HTTPService;
		private var proxy:IProxy;
		
		
		public function BaseHTTPService(service:HTTPService,proxy:IProxy)
		{
   			this.service = service;
   			this.proxy = proxy;
		}
		
		public function execute(backendMethod:String,parameters:Array):void
        {
			var responder:Responder = new Responder(onResult,onFault);
			var asyncToken:AsyncToken = service.send(parameters);
					
			asyncToken.addResponder(responder);
        }
		
		
		private function onResult(event:ResultEvent):void
		{
		    proxy.onServiceSuccess(event);
		}
		
		private function onFault(event:FaultEvent):void
		{   
			proxy.onServiceFault(event);
		}
		

	}
}